/**
 * 
 */
package neptune.manager.completer;

import neptune.manager.builder.MACAddressBuilder;
import neptune.manager.model.topology.MACAddress;
import neptune.manager.model.topology.NetworkInterface;
import neptune.manager.model.topology.Topology;
import neptune.manager.storage.ExperimentRepositoryException;
import neptune.manager.storage.StorageReadException;
import neptune.manager.storage.TopologyDefinitionException;
import neptune.manager.utils.DebugLog;
import neptune.manager.utils.Logger.LogContext;

/**
 * @author Roberto Bifulco [info@RobertoBifulco.it] [RobertoBifulco.it]
 * 
 */
public class NetworkInterfaceCompleter {

	public void completeInterface(NetworkInterface netIf, Topology actual)
			throws CompleterException {

		try {
			if (netIf.getMacAddress() == null
					|| netIf.getMacAddress().getAddress().equalsIgnoreCase("")) {

				LogContext context = new LogContext("NetworkCompletion");
				MACAddress mac = MACAddressBuilder.buildMACAddress(actual,
						context);

				DebugLog.printDetailedLog("Built MAC address: " + mac,
						NetworkInterfaceCompleter.class.getSimpleName());

				netIf.setMacAddress(mac);
			}
		} catch (ExperimentRepositoryException e) {
			DebugLog.printDetailedLog(e.getMessage(),
					NetworkInterfaceCompleter.class.getSimpleName());
			throw new CompleterException(e);
		} catch (StorageReadException e) {
			DebugLog.printDetailedLog(e.getMessage(),
					NetworkInterfaceCompleter.class.getSimpleName());
			throw new CompleterException(e);
		} catch (TopologyDefinitionException e) {
			DebugLog.printDetailedLog(e.getMessage(),
					NetworkInterfaceCompleter.class.getSimpleName());
			throw new CompleterException(e);
		}
	}

}
